﻿import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { NestExpressApplication } from '@nestjs/platform-express';
import { ValidationPipe } from '@nestjs/common';
import { join } from 'path';
import * as fs from 'fs';
// import { fileUpload  } from 'express-fileupload';
// import bodyParser from 'body-parser';
// import bodyParserXml from 'body-parser-xml';
const bodyParser = require('body-parser');
require('body-parser-xml')(bodyParser);

// bodyParserXml(bodyParser);
async function bootstrap() {
  // const httpsOptions = {
  //   key: fs.readFileSync('D:/BtSoft/apache/conf/ssl/8281461_bangkeedu.com/8281461_bangkeedu.com.key'),
  //   cert: fs.readFileSync('D:/BtSoft/apache/conf/ssl/8281461_bangkeedu.com/8281461_bangkeedu.com.pem')
  // }
  const app = await NestFactory.create<NestExpressApplication>(AppModule, {
    // httpsOptions,
    cors: true
  });
  // app.use(fileUpload({
  //   useTempFiles: true,
  //   tempFileDir: "/tmp/"
  // }))
  app.use(
    bodyParser.xml({
      xmlParseOptions: {
        explicitArray: false, // 始终返回数组。默认情况下只有数组元素数量大于 1 是才返回数组。
      },
    }),
  );
  app.useStaticAssets(join(__dirname, 'public'), {
    extensions: ['html', 'mp4', 'jpg', 'png', 'flv', 'avi', 'mov', 'wmv']
  });
  app.useGlobalPipes(new ValidationPipe());
  await app.listen(3000);
}
bootstrap();